package dao

import (
    "errors"
    __ "driver_srv/basic/driverproto"
    "driver_srv/handler/models"
)

// DriverCarpoolAddressList 查询司机顺风车地址列表
func DriverCarpoolAddressList(in *__.DriverCarpoolAddressListReq) (*__.DriverCarpoolAddressListResp, error) {
	if in.DriverId <= 0 {
		return nil, errors.New("司机ID不能为空")
	}
	// 校验司机存在
	var driver models.Driver
	driver.Id = uint32(in.DriverId)
	if err := driver.FindDriverById(); err != nil {
		return nil, errors.New("司机信息不存在")
	}

    // 读取 city 表作为顺风车地址列表
    var city models.City
    cityList, err := city.FindList()
    if err != nil {
        return nil, errors.New("查询城市列表失败：" + err.Error())
    }

    // 组装响应（地址=城市名，更新日期=城市更新时间）
	resp := &__.DriverCarpoolAddressListResp{
		DriverId:   in.DriverId,
		DriverName: driver.Name,
	}
    for i, item := range cityList {
		resp.Items = append(resp.Items, &__.CarpoolAddressItem{
			Seq:       int32(i + 1),
            Address:   item.City,
            UpdatedAt: item.UpdatedAt.Format("2006-01-02"),
		})
	}
	return resp, nil
}


